﻿#ifndef AUDIO_CONVERT_H_
#define AUDIO_CONVERT_H_

extern "C"
{
#include <libavutil/time.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavutil/opt.h>
#include <libavutil/audio_fifo.h>
};

class  AudioConvert
{

public:
    AudioConvert();

    virtual ~AudioConvert();

    int getInSampleRate() const;

    int getInChannels() const;

    AVSampleFormat getInSampleFormat() const;

    int getOutSampleRate() const;

    int getOutChannels() const;

    AVSampleFormat getOutSampleFormat() const;

    void setParam(int inSampleRate,int inChannels,AVSampleFormat inSampleFormat,
                  int outSampleRate,int outChannels,AVSampleFormat outSampleFormat);

    bool create();

    bool trans(AVFrame *frame);

    AVFrame *readFrame(int samples);

private:

    SwrContext      *swrContext;

    uint8_t         **buffer;

    int             inSampleRate;

    int             inChannels;

    int             inSamples;

    AVSampleFormat  inSampleFormat;

    int             outSampleRate;

    int             outChannels;

    int64_t         maxOutSamples;

    AVSampleFormat  outSampleFormat;

    int             outLineSize[8];

    AVAudioFifo     *fifo;

    int64_t         curPts;
};


#endif //AUDIO_CONVERT_H_
